/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = __weblogic_browse_req.c                            */
/*  NOTE      =                                                    */
/*  DATE      = 2016/04/11 by jikw                                 */
/*******************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include <corba/corba_comm.h>
#include <corba/corba_core.h>
#include <corba/ejb_comm.h>
#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "frbyte_buffer.h"
#include "frlist.h"
#include "frreport_comm.h"
#include "apmtest_cunit.h"
#include "apmtest_comm.h"

#include "../../../src/module/corba/config.h"

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

extern int __weblogic_browse_req(Wls_jms_session *p_st_session
                                  , Frreport_body_data *p_st_body_data);

static void case1(void)
{
    Wls_jms_session *p_st_session = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Conntrack *p_st_conn = NULL;
    int i_ret = 0;

    p_st_conn = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_conn, 0x00, sizeof(Conntrack));

    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;
    p_st_conn->st_l7_analyzer.p_st_l7_module = (L7_module *)"1";

    p_st_body_data = frreport_body_new_l7(p_st_conn);

//    p_st_session = (Wls_jms_session *)frmalloc(sizeof(Wls_jms_session));
//    memset(p_st_session, 0x00, sizeof(Wls_jms_session));

    i_ret = __weblogic_browse_req(p_st_session, p_st_body_data);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    frfree(p_st_session);
    frfree(p_st_conn);
    frreport_body_free(&p_st_body_data);

    return;
}

static void case2(void)
{
    Wls_jms_session *p_st_session = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    //Conntrack *p_st_conn = NULL;
    int i_ret = 0;

//    p_st_conn = frmalloc(sizeof(Conntrack));
//    memset(p_st_conn, 0x00, sizeof(Conntrack));
//
//    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;
//    p_st_conn->st_l7_analyzer.p_st_l7_module = (void *)"1";
//
//    p_st_body_data = frreport_body_new_l7(p_st_conn);

    p_st_session = (Wls_jms_session *)frmalloc(sizeof(Wls_jms_session));
    memset(p_st_session, 0x00, sizeof(Wls_jms_session));

    i_ret = __weblogic_browse_req(p_st_session, p_st_body_data);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    frfree(p_st_session);

    return;
}

static void case3(void)
{
    Wls_jms_session *p_st_session = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Conntrack *p_st_conn = NULL;
    int i_ret = 0;

    p_st_conn = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_conn, 0x00, sizeof(Conntrack));

    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;
    p_st_conn->st_l7_analyzer.p_st_l7_module = (L7_module *)"1";

    p_st_body_data = frreport_body_new_l7(p_st_conn);

    p_st_session = (Wls_jms_session *)frmalloc(sizeof(Wls_jms_session));
    memset(p_st_session, 0x00, sizeof(Wls_jms_session));

    i_ret = __weblogic_browse_req(p_st_session, p_st_body_data);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_STRING_EQUAL(p_st_session->p_title, "PEEK");

    frfree(p_st_session->p_title);
    frfree(p_st_session);
    frfree(p_st_conn);
    frreport_body_free(&p_st_body_data);

    return;
}

static void case4(void)
{
    Wls_jms_session *p_st_session = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Conntrack *p_st_conn = NULL;
    int i_ret = 0;

    p_st_conn = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_conn, 0x00, sizeof(Conntrack));

    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;
    p_st_conn->st_l7_analyzer.p_st_l7_module = (L7_module *)"1";

    p_st_body_data = frreport_body_new_l7(p_st_conn);

    p_st_session = (Wls_jms_session *)frmalloc(sizeof(Wls_jms_session));
    memset(p_st_session, 0x00, sizeof(Wls_jms_session));
    p_st_session->p_queue = frstrdup("testQueue");

    i_ret = __weblogic_browse_req(p_st_session, p_st_body_data);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_STRING_EQUAL(p_st_session->p_title, "PEEK testQueue");

    frfree(p_st_session->p_queue);
    frfree(p_st_session->p_title);
    frfree(p_st_session);
    frfree(p_st_conn);
    frreport_body_free(&p_st_body_data);

    return;
}

int add_suite__weblogic_browse_req(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __weblogic_browse_req()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", case1);
    CU_add_test(pSuite, "case2", case2);
    CU_add_test(pSuite, "case3", case3);
    CU_add_test(pSuite, "case4", case4);

    return FR_SUCC;

}


